package game;

import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.LayoutManager;

import javax.swing.JScrollPane;

public class MyCustomLayout implements LayoutManager 
{
	private Container parent;
	
	public MyCustomLayout(Container c)
	{
		parent = c;
	}
	
	
	@Override
	public void addLayoutComponent(String name, Component comp) 
	{
		System.out.println(name);
	}

	@Override
	public void removeLayoutComponent(Component comp) 
	{
		System.out.println("remove");

	}

	@Override
	public Dimension preferredLayoutSize(Container parent) 
	{
		Dimension dim = new Dimension();
		dim.setSize(parent.getWidth(), this.parent.getHeight() );
		return dim;
	}

	@Override
	public Dimension minimumLayoutSize(Container parent) 
	{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void layoutContainer(Container parent) 
	{
		int x = 0;
		int y = 0;
		for (int idx = 0; idx < parent.getComponentCount(); idx++)
		{
			int width = 0;
			int height = this.parent.getHeight() - 1;
			Component currentComponent = parent.getComponent(idx);
			if (currentComponent instanceof JScrollPane) 
			{
				width = ( (JScrollPane)currentComponent).getViewport().getWidth();
			}
			currentComponent.setBounds(x, y, width, height);
			x += currentComponent.getWidth();
		}
	}

}
